<?php

require_once("./Install.php");

class InstallView{
	
	private $Install_clicked = "Install";
	private $Uninstall_clicked = "Uninstall";
	
	private $host = "host";
	private $user = "user";
	private $pass = "pass";
	private $db = "db";
	
	//Private message shown by installform
	private $message;
	
	/**
	 * @Access Public
	 * @Param - 
	 * @Return HTML - a div, with a form for submiting DB settings 
	 */
	public function renderInstallForm(){
		return "<div class='installDiv'>
			<form method='post' action=''>
				<fieldset>
					<legend><strong>Enter your database info:</strong></legend>
					$this->message
					<label for='host'>Host:</label>
			    	<input type='text' size='30' id='Host' name='$this->host'/><br />
			    	
			    	<label for='host'>UserName:</label>
			    	<input type='text' size='30' id='User' name='$this->user'/><br />
			    	
			    	<label for='host'>Password:</label>
			    	<input type='text' size='30' id='Pass' name='$this->pass'value=''/><br />
			    	
			    	<label for='host'>DatabaseName</label>
			    	<input type='text' size='30' id='DB' name='$this->db'/><br />
			    	
			    	<input type='Submit' name='$this->Install_clicked' value='Install' />
			    	
				</fieldset>
			</form>
		</div>";
	}
	
	/**
	 * Generate HTML output allready installed
	 * @Access Public
	 * @Param - 
	 * @Return HTML, Showing that the App is installed and working correctly
	 */
	public function generateAllreadyInstalledOutPut(){
		return "<h1>IMG - Yaic is installed and working correctly!</h1>
				<h3>A test connection was successfully astablished and terminated, the option to Un-Install or change settings will come in the next version of IMG-YAIC<h3>
				<a href='index.php'>Click me to get started</a>
				<h2>Or Uninstall YAIC!</h2>
				<form method='post' action=''>
					<input type='Submit' name='$this->Uninstall_clicked' value='Uninstall' />
				</form>";
	}
	
	/**
	 * Findout if user clicked Install
	 * @Access Public
	 * @Param - 
	 * @Return Bool if user tried to submit form or not
	 */
	public function didUserClickInstall(){
		if(isset($_POST[$this->Install_clicked])){
			return true;
		}
		return false;
	}
	
	/**
	 * Findout if user clicked uninstall
	 * @access public
	 * @param -
	 * @return bool
	 */
	public function didUserClickUninstall(){
		if(isset($_POST[$this->Uninstall_clicked])){
			return true;
		}
		return false;
	}
	
	/**
	 * Get submited input from userfrom
	 * @Access public 
	 * @Param -
	 * @Return Array with information submited by user
	 */
	public function getDataBaseInfoFromForm(){
		if(isset($_POST[$this->db]) AND
		   isset($_POST[$this->host]) AND
		   isset($_POST[$this->user]) AND
		   isset($_POST[$this->pass])){
					
			$returnArray[InstallHandler::DBUSER] = $_POST[$this->user];
			$returnArray[InstallHandler::DBPASS] = $_POST[$this->pass];	
			$returnArray[InstallHandler::DB] = $_POST[$this->db];	
			$returnArray[InstallHandler::DBHOST] = $_POST[$this->host];	
			
			return $returnArray;
		}
		$this->message = "<p>All fields needs to be filled!</p>";
		return false;
	}
	
	/**
	 * Make sure noone is messing with our stuff
	 * @Access Public
	 * @Param -
	 * @Return Bool if all fields are "valid", in this case have content
	 */
	public function isValidForm(){
		if(isset($_POST[$this->db]) AND
		   isset($_POST[$this->host]) AND
		   isset($_POST[$this->user])){
				return true;
		}
		$this->message = "<p>All fields needs to be valid!</p>";
		return false;
	}
	
	/**
	 * @Access public
	 * @Param - 
	 * @return - 
	 * When called it sets the private message to failed
	 */
	public function generateFailMessage(){
		$this->message = "<p>Fail! Something when wrong, please try again.</p>";
	}
	
}